package org.example.service.impl;

import org.apache.catalina.User;
import org.example.mapper.UserMapper;
import org.example.model.UserInfo;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserInfo selectUserByName(String username) {
        return userMapper.selectUserByName(username);
    }

    @Override
    public UserInfo getUserById(Integer userId) {
        return userMapper.selectUserById(userId);
    }

    @Override
    public UserInfo getAuthorByBlogId(Integer blogId) {
        // 根据博客id获取作者id
        Integer user_id = userMapper.getUserIdByBlogId(blogId);
        if (user_id != null && user_id > 0) {
            UserInfo userInfo = userMapper.selectUserById(user_id);
            return userInfo;
        }
        return null;
    }
}
